package com.kylin.common.util;

import com.kylin.common.collect.MapUtils;
import com.kylin.common.io.PropertiesUtils;
import com.kylin.common.lang.StringUtils;

import java.util.Map;

/**
 * 全局配置工具类
 *
 * @author wuhao
 * @version 1.0 - 2019-06-23
 */
public class Global {

    private static final Global INSTANCE = new Global();

    /**
     * 属性值map集合
     */
    private static Map<String,String> props = MapUtils.newHashMap();

    /**
     * 获取某个属性值
     * @param  key
     * @return
     * @version 1.0  by wuhao at 2019/7/11
     */
    public static String getProperty(String key){
        String value = props.get(key);
        if(StringUtils.isBlank(value)){
            //多配置值，参考jeesite

            if(StringUtils.isNotBlank(value = PropertiesUtils.getInstance().getProperty(key))){
                props.put(key,value);
            }

        }
        return value;
    }

    /**
     * 获取某个属性值
     * @param key
     * @return defValue 不存在，则返回默认值
     * @version 1.0  by wuhao at 2019/7/11
     */
    public static final String getProperty(String key,String defValue){
        String value = "";
        return StringUtils.isBlank(value = getProperty(key)) ? defValue : value;
    }
}
